package com.he.security.rscoket.uthentication;

import com.he.security.core.Authentication;
import com.he.security.core.context.ReactiveSecurityContextHolder;
import com.he.security.core.context.SecurityContext;
import com.he.security.rsocket.api.PayloadExchange;
import com.he.security.rsocket.api.PayloadInterceptorChain;
import reactor.core.publisher.Mono;

public class AuthenticationPayloadInterceptorChain implements PayloadInterceptorChain {

    private Authentication authentication;


    @Override
    public Mono<Void> next(PayloadExchange exchange) {
        return ReactiveSecurityContextHolder.getContext().map(SecurityContext::getAuthentication).doOnNext(this::setAuthentication).then();
    }


    public Authentication getAuthentication() {
        return this.authentication;
    }

    public void setAuthentication(Authentication authentication) {
        this.authentication = authentication;
    }
}
